package com.jiuyi.controller;

import com.jiuyi.common.R;
import com.jiuyi.dto.AdminDishDto;
import com.jiuyi.entity.Dish;
import com.jiuyi.service.Impl.DishServiceImpl;
import com.jiuyi.vo.AdminSelectDishListVo;
import com.jiuyi.vo.AdminSelectDishVo;
import com.jiuyi.vo.AdminUpdateDishVo;
import com.jiuyi.vo.DishListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * DATA: 2022/10/20
 * Author: 晨夕
 */
@RestController
@RequestMapping("/dish")
public class DishController {

    @Autowired
    private DishServiceImpl dishServiceImpl;

    /**
     * 添加菜品
     */
    @PostMapping
    public R addDish(@RequestBody AdminDishDto adminDishDto){
        return dishServiceImpl.addDish(adminDishDto);
    }

    /**
     * 查询菜品
     */
    @GetMapping("/page")
    public R<AdminSelectDishVo> selectDish(int page, int pageSize, String name){
        return dishServiceImpl.selectDish(page,pageSize,name);
    }

    /**
     * 根据id查询数据
     */
    @GetMapping("/{id}")
    public R<AdminUpdateDishVo> selectDishById(@PathVariable("id") Long id){
        return dishServiceImpl.selectDishById(id);
    }
    /**
     * 修改菜品
     */
    @PutMapping
    public R updateDish(@RequestBody AdminDishDto adminDishDto){
        return dishServiceImpl.updateDish(adminDishDto);
    }
    /**
     * 删除菜品
     */
    @DeleteMapping
    public R deleteDish(Long[] ids){
        return dishServiceImpl.deleteDish(ids);
    }
    /**
     * 停售菜品
     */
    @PostMapping("/status/0")
    public R stopSell(Long[] ids){
        return dishServiceImpl.stopSell(ids);
    }
    /**
     * 起售菜品
     */
    @PostMapping("/status/1")
    public R startSell(Long[] ids){
        return dishServiceImpl.startSell(ids);
    }
    /**
     * 查询菜品集合
     */
    @GetMapping("/list")
    public R<List<AdminSelectDishListVo>> dishList(Dish dish){
        return dishServiceImpl.dishList(dish);
    }
}
